package com.xinxin.o2o.controller.indexcontroller;

import com.xinxin.o2o.enums.GlobalCode;
import com.xinxin.o2o.model.HeadLine;
import com.xinxin.o2o.response.Response;
import com.xinxin.o2o.service.HeadLineService;
import com.xinxin.o2o.service.ShopCategoryService;
import com.xinxin.o2o.util.ResponseUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author ShiXinXin
 * @date 2019-09-16 0:36
 */
@Api(tags = {"首页"}, produces = "application/json")
@RestController
@RequestMapping("/api/index")
public class IndexController {
    @Autowired
    private ShopCategoryService shopCategoryService;

    @Autowired
    private HeadLineService headLineService;

    @GetMapping("/shopcategories")
    public Response getShopCategories() {
        try {
            return ResponseUtil.success(shopCategoryService.getShopCategoryList(null));
        } catch (Exception e) {
            return ResponseUtil.error(GlobalCode.INNER_ERROR, e.getMessage());
        }
    }

    @GetMapping("/headlines")
    public Response getHeadLines() {
        try {
            HeadLine headLineCondition = new HeadLine();
            headLineCondition.setEnableStatus(1);
            return ResponseUtil.success(headLineService.getHeadLineList(headLineCondition));
        } catch (Exception e) {
            return ResponseUtil.error(GlobalCode.INNER_ERROR, e.getMessage());
        }
    }

}
